package com.ruoyi.project.business.controlcenter.iot.util;


import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MqttParamUtil {

    private final static String field_type = "type";

    /**
     *
     * @param index // io index
     * @param value // 0 关 1 开
     * @param type // 与开发板里面的事件对应 "pin" "blink" "blink_pwm"
     * @return
     */
    public static String getParams(Integer index, String mac, int value, String type) {
        JSONObject param = new JSONObject();
        param.put(field_type, type);
        param.put("data", "none");
        param.put("mac", mac);
        param.put("index", index);
        param.put("value", value); // 0 关 1 开
        String params = param.toJSONString();
        return params;
    }
    /**
     *
     * @param index // io index
     * @return
     */
    public static String getBlinkPwmParams(Integer index, String mac, Integer pmw) {
        JSONObject param = new JSONObject();
        param.put(field_type, "blink_pwm");
        param.put("mac", mac);
        param.put("index", index);
        param.put("pmw", pmw); // 占空比
        String params = param.toJSONString();
        return params;
    }
    public static String getPwmParams(Integer index, String mac, Integer pmw) {
        JSONObject param = new JSONObject();
        param.put(field_type, "pwm");
        param.put("mac", mac);
        param.put("index", index);
        param.put("pmw", pmw); // 占空比
        String params = param.toJSONString();
        return params;
    }
    public static String getPwmOffParams(Integer index, String mac) {
        JSONObject param = new JSONObject();
        param.put(field_type, "pwm_off");
        param.put("mac", mac);
        param.put("index", index);
        String params = param.toJSONString();
        return params;
    }
    public static String getBleAdvParam(String mac, String reqType, Integer seconds) {
        JSONObject param = new JSONObject();
        param.put("mac", mac);
        param.put(field_type, reqType);
        param.put("seconds", seconds);
        String params = param.toJSONString();
        return params;
    }
    public static String getSaveWifiParams(String ssid, String pwd, String mac) {
        JSONObject param = new JSONObject();
        // {type:"savewifi", "mac":"08:d1:f9:2a:1c:0c", "ssid":"1101", "pwd":"15821652637"}
        param.put(field_type, "savewifi");
        param.put("ssid", ssid);
        param.put("pwd", pwd);
        param.put("mac", mac);
        String params = param.toJSONString();
        return params;
    }

    public static String getBleAdvCancelParam(String mac) {
        JSONObject param = new JSONObject();
        param.put(field_type, "ble_adv_cancel");
        param.put("mac", mac);
        String params = param.toJSONString();
        return params;
    }
}
